package com.szh.zx.jvm.chapter13.java2;

import org.junit.Test;

/**
 * @author shkstart  shkstart@126.com
 * @create 2020  20:17
 */
public class StringExer1 {
    public static void main(String[] args) {
        String s = new String("a") + new String("b");//new String("ab")
        //在上一行代码执行完以后，字符串常量池中并没有"ab"

        String s2 = s.intern();

        System.out.println(s==s2);
        System.out.println("===");
        System.out.println(s2 == "ab");//jdk6:true  jdk8:true
        System.out.println(s == "ab");//jdk6:false  jdk8:true
    }
    @Test
    public void test(){
        String x = "ab";
        String s = new String("a") + new String("b");//new String("ab")
        
        String s2 = s.intern();

        System.out.println(x==s);
        System.out.println(s==s2);
        System.out.println(x==s2);
        System.out.println("==============");
        System.out.println(s2 == "ab");// true
        System.out.println(s == "ab");// false
    }
}
